<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改会员等级')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-memberLv-edit" th:object="${memberLv}">
            <input id="memberLvId" name="memberLvId" th:field="*{memberLvId}"  type="hidden">
			<div class="form-group">	
				<label class="col-sm-3 control-label">等级名称：</label>
				<div class="col-sm-8">
					<input id="name" name="name" th:field="*{name}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">等级LOGO：</label>
				<div class="col-sm-8">
					<input id="logo" name="logo" th:field="*{logo}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">会员折扣率：</label>
				<div class="col-sm-8">
					<input id="disCount" name="disCount" th:field="*{disCount}" class="form-control" type="text">
				</div>
			</div>
			<input type="hidden" id="hidden_preId" th:field="*{preId}">
			<div class="form-group">	
				<label class="col-sm-3 control-label">前一级别：</label>
				<div class="col-sm-8">
					<select id="preId" name="preId" class="form-control">
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">是否默认：</label>
				<div class="col-sm-8">
					<select name="defaultLv" th:field="*{defaultLv}" class="form-control">
						<option value="0">否</option>
						<option value="1">是</option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">升级所需积分：</label>
				<div class="col-sm-8">
					<input id="point" name="point" th:field="*{point}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" th:field="*{remark}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">过期时间：</label>
				<div class="col-sm-8">
					<input id="expireTime" name="expireTime" th:field="*{expireTime}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">过期时间单位</label>
				<div class="col-sm-8">
					<select name="expireTimeUnit" th:field="*{expireTimeUnit}" class="form-control">
						<option value="1">小时</option>
						<option value="2">天</option>
						<option value="3">月</option>
						<option value="4">年</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">状态</label>
				<div class="col-sm-8">
					<select id="disabled" name="disabled" th:field="*{disabled}" class="form-control">
						<option value="0">有效</option>
						<option value="1">无效</option>
					</select>
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "member/memberLv";

		$(function () {
			$('#preId').empty('');
			$('#preId').append('<option value="" selected="selected">无</option>');
			$.ajax({
				url: ctx + "member/memberLv/list",
				type: 'POST',
				data: {
					disabled: 0
				},
				success: function (result) {
					var perId = $('#hidden_preId').val();
					if (result.code == web_status.SUCCESS) {
						if (result.total > 0) {
							var rows = result.rows;
							rows.forEach(function (item, index) {
								if(item.memberLvId == perId) {
									$('#preId').append('<option value="' + item.memberLvId + '" selected="selected">' + item.name + '</option>');
								} else {
									$('#preId').append('<option value="' + item.memberLvId + '">' + item.name + '</option>');
								}
							});
						}
					} else {

					}
				}
			});
		});

		$("#form-memberLv-edit").validate({
			rules:{
				name:{
					required:true,
					maxlength: 100
				},
				disCount:{
					required:true,
					number:true,
					max:1,
					min:0
				},
				defaultLv:{
					required:true
				},
				point:{
					required:true,
					digits:true,
					min:0
				},
				expireTime:{
					required:true
				},
				expireTimeUnit:{
					required:true
				},
				disabled:{
					required:true
				}
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-memberLv-edit').serialize());
	        }
	    }
	</script>
</body>
</html>
